﻿using System;
using System.Collections.Generic;
using System.IO;

namespace BackupLibrary
{
    public class Settings
    {
        private Settings() { }
        private static Settings _instance;
        public static Settings Get
        {
            get
            {
                if (_instance == null)
                {
                    String path = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    path = System.IO.Path.GetDirectoryName(path);
                    if (File.Exists(path + "\\Settings.xml"))
                    {
                        _instance = new Serialization().DeserializeSettings(File.ReadAllText(path + "\\Settings.xml"));
                    }
                    else
                    {
                        _instance = new Settings();
                    }
                }
                return _instance;
            }
        }
        public List<LogEntry> _logs = new List<LogEntry>();

        public string EmailAdress { get; set; }
        public string Message { get; set; }
        public string WinrarPath { get; set; }
        public string ServerAddress { get; set; }
        public string UserId { get; set; }
        public string Password { get; set; }
        public string AccountType { get; set; }
        public string SenderMailAdress { get; set; }

        public void AddLog(LogEntry log)
        {
            _logs.Add(log);
        }

        public void SaveAll()
        {
            String path = System.Reflection.Assembly.GetExecutingAssembly().Location;
            path = System.IO.Path.GetDirectoryName(path);
            Serialization sr = new Serialization();
            string xml = sr.SerializeSettings(_instance);
            File.WriteAllText(path + "\\Settings.xml", xml);
        }
    }

    public class LogEntry
    {
        public DateTime Date { get; set; }
        public string Message { get; set; }
        public string Database { get; set; }
        public string Server { get; set; }
    }
}
